# 子类示例，用于处理特定的字段如 avatarPath
from datetime import timedelta
from src.main.domain.DataConverter import DataConverter
from src.main.util.ApplicationConfig import ApplicationConfig
from src.main.util.MinioClient import minio_client


class UserConverter(DataConverter):
    @classmethod
    def post_process_dict(cls, obj_dict):
        # 处理 avatarPath 字段
        obj_dict['avatarPath'] = cls.process_avatar_path(obj_dict.pop('avatarPath', None))
        # 可以在这里处理其他字段
        return obj_dict

    @staticmethod
    def process_avatar_path(avatar_path):
        if avatar_path:
            app_config = ApplicationConfig()
            minio_config = app_config.get_minio()
            bucket_name = minio_config.get('bucket_name')
            endpoint = minio_config.get('endpoint')
            access_key = minio_config.get('access_key')
            secret_key = minio_config.get('secret_key')
            object_name = avatar_path
            client = minio_client(endpoint, access_key, secret_key)
            return client.get_presigned_url(bucket_name, object_name, expires=timedelta(days=7))


